<?php

class Flag
{

    public function __construct()
    {
        
    }

    public function swth_control($gametype)
    {
        global $acl;
        global $curruser;
        global $conf;
        global $g_init_mode_6h;
        global $g_init_mode_3d;
        global $g_menu_enabled;
        global $g_gametype_3d;
        $rlt = array (1, 0, date("Y-m-d"));
        switch ($g_gametype_3d[$gametype]['type'])
        {
            case 0 :
                $psen_edit_mod = 1;
                $rs = getdb("select id,open from lotto where open>='" . date("Y-m-d") . "' order by open LIMIT 1");
                $lotto_id = intval($rs->f['id']);
                $open = $rs->f['open'];
                $rs->close();
                if (date("Y-m-d") == $open)
                {
                    $stopbet = $conf->get("stopbet");
                    if ($conf->get("startbet") <= date("Hi") && date("Hi") <= $stopbet)
                    {
                        $psen_edit_mod = 0;
                    }
                }
                $rlt = array ($psen_edit_mod, $lotto_id, $open);
                break;
            case 1 :
                $psen_edit_mod = 1;
                $rs = getdb("select id,open from lotto_{$g_gametype_3d[$gametype]['en']} where open>='" . date("Y-m-d") . "' order by open LIMIT 1");
                $lotto_id = 0 - 1;
                $open = "";
                if (!$rs->eof)
                {
                    $lotto_id = intval($rs->f['id']);
                    $open = $rs->f['open'];
                    $rs->close();
                    if (date("Y-m-d") == $open)
                    {
                        $stopbet = $conf->get("stopbet_{$g_gametype_3d[$gametype]['en']}");
                        if ($conf->get("startbet_{$g_gametype_3d[$gametype]['en']}") <= date("Hi") && date("Hi") <= $stopbet)
                        {
                            $psen_edit_mod = 0;
                        }
                    }
                }
                $rlt = array ($psen_edit_mod, $lotto_id, $open);
                break;
            case 2 :
            case 3 :
                $tbl = $g_gametype_3d[$gametype]['en'];
                $psen_edit_mod = 1;
                $nextDateFlag = false;
                $startbet = $conf->get("startbet_{$tbl}");
                $stopbet = $conf->get("stopbet_{$tbl}");
                if ($stopbet < $startbet)
                {
                    $nextDateFlag = true;
                }
                $now = date("Hi");
                $todayTime = systime();
                if ($nextDateFlag && $now < $stopbet)
                {
                    $today = date("Y-m-d", strtotime("-1 day"));
                }
                else
                {
                    $today = date("Y-m-d");
                }
                $open = $today;
                $lotto_id = 0 - 1;
                $rs = getdb("select id,open from lotto_{$tbl} where open>='{$today}' order by id ASC LIMIT 0,1");
                if (!$rs->eof)
                {
                    $lotto_id = intval($rs->f['id']);
                    $open = $rs->f['open'];
                    $rs->close();
                    if ($today == $open)
                    {
                        if ($nextDateFlag)
                        {
                            $addMin = 86460;
                        }
                        else
                        {
                            $addMin = 60;
                        }
                        $stoptime = $open . " " . substr($stopbet, 0, 2) . ":" . substr($stopbet, 2, 2) . ":00";
                        $stopInt = strtotime($stoptime) + $addMin;
                        $starttime = $open . " " . substr($startbet, 0, 2) . ":" . substr($startbet, 2, 2) . ":00";
                        $startInt = strtotime($starttime);
                        if ($startInt <= $todayTime && $todayTime <= $stopInt)
                        {
                            $psen_edit_mod = 0;
                        }
                    }
                }
                $rlt = array ($psen_edit_mod, $lotto_id, $open);
                break;
        }
        return $rlt;
    }

}

class k_users
{

    public function __construct()
    {
        
    }

    public function top_bar($gametype, $title, $funlist)
    {
        return "<table bgcolor=#B3B3B3 border=0 cellpadding=0 cellspacing=1 width=758><tr><td>" . "<table class=table0 width='100%' border=0 cellpadding=0 cellspacing=0><tr><td class='title0 bgImg_{$gametype}'>" . "<table width=100% border=0 cellpadding=1 cellspacing=0><tr><td>{$title}<td align=right>{$funlist}</table></table></table>";
    }

    public function amount_6h($data)
    {
        return "<tr><td class=paper6h>{$data[0]}信用额度</td><td class=td2 colspan=3>\r\n\t\t<input maxlength='100' name='amount' value={$data[1]} size='10' onkeypress=\"return OnlyInt()\"\r\n\t\tonkeyup=\"document.all.camount.innerHTML=n2c(this.value)\">&#12288;<font color=red id=camount></font>\r\n\t\t<font color=red>● 最大额度为：{$data[2]}</font>\r\n\t\t</td></tr>";
    }

    public function amount($data)
    {
        return "<tr><td class=".($data[0]=="时时彩共用"?"paper3d":"td1").">{$data[0]}信用额度</td><td class=td2  colspan=3>\r\n\t\t<input maxlength='100' name=amount_{$data[1]} value={$data[2]} size='10' onkeypress=\"return OnlyInt()\"\r\n\t\tonkeyup=\"document.all.camount_{$data[1]}.innerHTML=n2c(this.value)\">&#12288;<font color=red id=camount_{$data[1]}></font>\r\n\t\t<font color=red>● 最大额度为：{$data[3]}</font>\r\n\t\t</td></tr>";
    }
	public function maount_info()
	{
		return '';
		return '<tr >
                        <td class="td1">额度使用说明</td>
                        <td class="td2"  colspan="3" style="color:#4a4a4a;">
                          ◎<strong style="color:red">信用额度:</strong> 每日结帐後，会将额度「补回至初始额度」。<br />
                          ◎<strong style="color:red">浮动额度:</strong> 如会员额度10万，今日输5万，隔日额度只会有五万。输完必须由上一个阶层对下阶层充值。<br />
                        </td>
                      </tr>';
	}
}

class Show_subsidary extends k_users
{

    public function __construct()
    {
        
    }

    public function amount_6h($data)
    {
        return "<tr><td nowrap class=paper6h>{$data[0]}信用额度</td><td class=td2 colspan=3>\r\n\t\t<input maxlength='100' name='amount' value={$data[1]} size='10' onkeypress=\"return OnlyInt()\"\r\n\t\tonkeyup=\"document.all.camount.innerHTML=n2c(this.value)\">&#12288;<font color=red id=camount></font></td>\r\n\t\t</tr>";
    }

    public function amount($data)
    {
        return "<tr><td nowrap class=".($data[0]=="时时彩共用"?"paper3d":"td1").">{$data[0]}信用额度</td><td class=td2 colspan=3>\r\n\t\t<input maxlength='100' name=amount_{$data[1]} value={$data[2]} size='10' onkeypress=\"return OnlyInt()\"\r\n\t\tonkeyup=\"document.all.camount_{$data[1]}.innerHTML=n2c(this.value)\">&#12288;<font color=red id=camount_{$data[1]}></font></td>\r\n\t\t</tr>";
    }

    public function percent_6h($data)
    {
		return "<tr  zc=true>
            <td class=paper{$data[0]}>{$data[1]}占成设置</td>
            <td ><input id=\"sta_syn\" class=\"nobtnclass colorBtnGray\" type=\"button\" value=\"以我同步\"></td>
            <td ><input id=mpercent name=mpercent value={$data[2]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %</td>
			<td style='color:#ff0000'>$data[4]</td>
            <td></td>
		   </tr>";
        //return "<tr><td nowrap class=paper{$data[0]}>{$data[1]}占成设置<input id=\"sta_syn\" class=\"nobtnclass colorBtnGray\" type=\"button\" value=\"以我同步\"></td>\r\n\t\t<td class=td2 colspan=3>大股东最大为 <input id=mpercent name=mpercent value={$data[2]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %\r\n\t\t<input type=checkbox id={$data[3]} name={$data[3]}>锁定下线最大占成 &#12288; <font color=red>● 最大不得超过{$data[4]}</font></td></tr>";<input type=checkbox id={$data[3]} name={$data[3]}>
    }

    public function percent($data)
    {
		return "<tr  zc=true>
            <td class=paper{$data[0]}>{$data[1]}占成设置</td>
            <td ><input id=\"sta_syn{$data[0]}\" class=\"nobtnclass colorBtnGray\" type=\"button\" value=\"以我同步\"></td>
            <td ><input id=mpercent{$data[0]} name=mpercent_{$data[0]} value={$data[2]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %</td>
			<td style='color:#ff0000'>$data[4]</td>
            <td><input type=checkbox id={$data[3]} name={$data[3]}></td>
		   </tr>";
        //return "<tr><td nowrap class=paper{$data[0]}>{$data[1]}占成设置<input id=\"sta_syn{$data[0]}\" class=\"nobtnclass colorBtnGray\" type=\"button\" value=\"以我同步\"></td>\r\n\t\t<td class=td2 colspan=3>大股东最大为  %\r\n\t\t<input type=checkbox id={$data[3]} name={$data[3]}>锁定下线最大占成 &#12288; <font color=red>● 最大不得超过{$data[4]}</font></td></tr>";
    }

    public function protmod($data)
    {
        return "<tr><td nowrap class={$data[0]}>{$data[1]}功能</td><td class=td2 colspan=3>\r\n\t\t<input type=radio name={$data[2]} value={$data[3]}>启用\r\n\t\t<input type=radio name={$data[2]} value={$data[4]}>停用</td>\r\n\t\t</tr>";
    }

    public function reduce_6h($data)
    {
        //return "<tr><td nowrap class=paper6h>六合彩特码减倍</td><td class=td2 colspan=3>公司减倍\r\n\t\t<input name=rate0 value={$data['0']} size='4' maxlength='5'>下层减倍功能\r\n\t\t<input type=radio name=rate0mod value={$data[1]}>启用\r\n\t\t<input type=radio name=rate0mod value={$data[2]}>停用\r\n\t\t<input type=checkbox name={$data[3]}>八面同步</td>\r\n\t\t</tr>";
    }

}

class Show_shareowner extends k_users
{

    public function __construct()
    {
        
    }

    public function percent_6h($data)
    {
		return "<tr  zc=true>
            <td rowspan=2 class=paper{$data[0]}>{$data[1]}占成设置</td>
            <td ><input type='button' id='btn_{$data[0]}' name='btn_{$data[0]}' onclick='upzc(this)' value='与我1同步'></td>
            <td ><input type='text' name=percent0 value={$data[2]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %</td>
            <td><input type='text' name=percent1 value={$data[3]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %</td>
            <td><input type='text' name=percent2 value={$data[4]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"></td>
			<td style='color:#ff0000'>$data[8]</td>
            <td><input type='text' name=mpercent value={$data[5]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %</td>
            <td></td>
		   </tr>
		   <tr>
		   	<td colspan=7 style='color:#ff0000'>● 收飞占成为 0 时，[连码]、[连肖]、[连尾]、[自选不中]等,无法自动走飞。</td>
		   </tr>";
        //return "<tr><td class=paper{$data[0]}>{$data[1]}占成设置</td><td class=td2>{$data[6]}最少占\r\n\t\t<input name=percent0 value={$data[2]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %&#12288;{$data[6]}最大占\r\n\t\t<input name=percent1 value={$data[3]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %&#12288;{$data[6]}收飞最大占\r\n    <input name=percent2 value={$data[4]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %<br>{$data[7]}可占成数\r\n\t\t<input name=mpercent value={$data[5]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> % <input type=checkbox name={$data[9]}>锁定下线最大占成 &#12288;<br>\r\n\t\t<font color=red>● {$data[6]}最少占成＋{$data[7]}可占成数不可比 <b>" . $data[8] . "</b> 多，{$data[6]}最大占成不可比最少占成小<br/>\r\n\t\t                ● 收飞占成为 0 时，[连码]、[连肖]、[连尾]、[自选不中]等,无法自动走飞。</font>\r\n    </td></tr>";<input type=checkbox name={$data[9]}>
    }

    public function percent($data)
    {
		return "<tr  zc=true>
            <td class=paper{$data[0]}>{$data[1]}占成设置</td>
            <td ><input type='button' id='btn_{$data[0]}' name='btn_{$data[0]}' onclick='upzc(this)' value='与我同步'></td>
            <td ><input type='text' name=percent0_{$data[0]} value={$data[2]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %</td>
            <td><input type='text' name=percent1_{$data[0]} value={$data[3]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %</td>
            <td><input type='text' name=percent2_{$data[0]} value={$data[4]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"></td>
			<td style='color:#ff0000'>$data[8]</td>
            <td><input type='text' name=mpercent_{$data[0]} value={$data[5]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %</td>
            <td><input type=checkbox name={$data[9]}></td>
		   </tr>";
        //return "<tr><td class=paper{$data[0]}>{$data[1]}占成设置</td><td class=td2>{$data[6]}最少占\r\n\t\t<input name=percent0_{$data[0]} value={$data[2]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %&#12288;{$data[6]}最大占\r\n\t\t<input name=percent1_{$data[0]} value={$data[3]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %&#12288;{$data[6]}收飞最大占\r\n\t\t<input name=percent2_{$data[0]} value={$data[4]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %<br>{$data[7]}可占成数\r\n\t\t<input name=mpercent_{$data[0]} value={$data[5]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> % <input type=checkbox name={$data[9]}>锁定下线最大占成 &#12288;<br>\r\n\t\t<font color=red>● {$data[6]}最少占成＋{$data[7]}可占成数不可比 <b>" . $data[8] . "</b> 多，{$data[6]}最大占成不可比最少占成小</font>\r\n\t\t</td></tr>";
    }

}

class Show_genagent extends k_users
{

    public function __construct()
    {
        
    }

    public function percent_6h($data)
    {
		return "<tr  zc=true>
            <td rowspan=2 class=paper{$data[0]}>{$data[1]}占成设置</td>
            <td ><input type='button' id='btn_{$data[0]}' name='btn_{$data[0]}' onclick='upzc(this)' value='与我同步'></td>
            <td ><input type='text' name=percent0 value={$data[2]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %</td>
            <td><input type='text' name=percent1 value={$data[3]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %</td>
            <td><input type='text' name=percent2 value={$data[4]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"></td>
			<td style='color:#ff0000'>$data[8]</td>
            <td><input type='text' name=mpercent value={$data[5]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %</td>
            <td></td>
		   </tr>
		   <tr>
		   	<td colspan=7 style='color:#ff0000'>● 收飞占成为 0 时，[连码]、[连肖]、[连尾]、[自选不中]等,无法自动走飞。</td>
		   </tr>";
        //return "<tr><td class=paperpercent_6h{$data[0]}>{$data[1]}占成设置</td><td class=td2>{$data[6]}最少占\r\n\t\t<input name=percent0 value={$data[2]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %&#12288;{$data[6]}最大占\r\n\t\t<input name=percent1 value={$data[3]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %&#12288;{$data[6]}收飞最大占\r\n    <input name=percent2 value={$data[4]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %<br>{$data[7]}可占成数\r\n\t\t<input name=mpercent value={$data[5]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> % <input type=checkbox name={$data[9]}>锁定下线最大占成 &#12288;<br>\r\n\t\t<font color=red>● {$data[6]}最少占成＋{$data[7]}可占成数不可比 <b>" . $data[8] . "</b> 多，{$data[6]}最大占成不可比最少占成小<br/>\r\n\t\t                ● 收飞占成为 0 时，[连码]、[连肖]、[连尾]、[自选不中]等,无法自动走飞。</font>\r\n    </td></tr>";<input type=checkbox name={$data[9]}>
    }

    public function percent($data)
    {
		return "<tr  zc=true>
            <td class=paper{$data[0]}>{$data[1]}占成设置</td>
            <td ><input type='button' id='btn_{$data[0]}' name='btn_{$data[0]}' onclick='upzc(this)' value='与我同步'></td>
            <td ><input type='text' name=percent0_{$data[0]} value={$data[2]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %</td>
            <td><input type='text' name=percent1_{$data[0]} value={$data[3]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %</td>
            <td><input type='text' name=percent2_{$data[0]} value={$data[4]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"></td>
			<td style='color:#ff0000'>$data[8]</td>
            <td><input type='text' name=mpercent_{$data[0]} value={$data[5]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %</td>
            <td><input type=checkbox name={$data[9]}></td>
		   </tr>";
        //return "<tr><td class=paper{$data[0]}>{$data[1]}占成设置</td><td class=td2>{$data[6]}最少占\r\n\t\t<input name=percent0_{$data[0]} value={$data[2]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %&#12288;{$data[6]}最大占\r\n\t\t<input name=percent1_{$data[0]} value={$data[3]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %&#12288;{$data[6]}收飞最大占\r\n\t\t<input name=percent2_{$data[0]} value={$data[4]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> %<br>{$data[7]}可占成数\r\n\t\t<input name=mpercent_{$data[0]} value={$data[5]} size='3' maxlength='3' onkeypress=\"return OnlyInt()\"> % <input type=checkbox name={$data[9]}>锁定下线最大占成 &#12288;<br>\r\n\t\t<font color=red>● {$data[6]}最少占成＋{$data[7]}可占成数不可比 <b>" . $data[8] . "</b> 多，{$data[6]}最大占成不可比最少占成小</font>\r\n\t\t</td></tr>";

	}

}

class Show_agent extends k_users
{

    public function __construct()
    {
        
    }

    public function percent_6h($data)
    {
		return "<tr  zc=true>
            <td rowspan=2 class=paper{$data[0]}>{$data[1]}占成设置</td>
            <td ><input type='button' id='btn_{$data[0]}' name='btn_{$data[0]}' onclick='upzc(this)' value='与我同步'></td>
            <td ><input type='text' name=percent0 value={$data[2]} size='3' maxlength='2' onkeypress=\"return OnlyInt()\"> %</td>
            <td><input type='text' name=percent2 value={$data[3]} size='2' maxlength='2' onkeypress=\"return OnlyInt()\"> %</td>
            <td style='color:#ff0000'>$data[7]</td>
            <td><input type='text' name=mpercent value={$data[4]} size='3' maxlength='2' onkeypress=\"return OnlyInt()\"> %</td>
           </tr>
		   <tr>
		   	<td colspan=5 style='color:#ff0000'>● 收飞占成为 0 时，[连码]、[连肖]、[连尾]、[自选不中],无法自动走飞。</td>
		   </tr>";
        //return "<tr><td class=paper{$data[0]}>{$data[1]}占成设置</td><td class=td2>{$data[5]}占成\r\n\t\t<input name=percent0 value={$data[2]} size='2' maxlength='2' onkeypress=\"return OnlyInt()\"> %&#12288;{$data[5]}收飞最大占成\r\n\t\t<input name=percent2 value={$data[3]} size='2' maxlength='2' onkeypress=\"return OnlyInt()\"> %&#12288;{$data[6]}占成\r\n\t\t<input name=mpercent value={$data[4]} size='2' maxlength='2' onkeypress=\"return OnlyInt()\"> %<br>\r\n\t\t<font color=red>● AA{$data[5]}占成＋{$data[6]}占成不可比  " . $data[7] . " 多</font>\r\n\t\t</td></tr>";
    }

    public function percent($data)
    {
		return "<tr zc=true>
            <td class=paper{$data[0]}>{$data[1]}占成设置</td>
            <td><input type='button' id='btn_{$data[0]}' name='btn_{$data[0]}' onclick='upzc(this)' value='与我同步'></td>
            <td><input type='text' name='percent0_{$data[0]}' value={$data[2]} size='3' maxlength='2' onkeypress=\"return OnlyInt()\"> %</td>
            <td><input type='text' name='percent2_{$data[0]}' value={$data[3]} size='2' maxlength='2' onkeypress=\"return OnlyInt()\"> %</td>
            <td style='color:#ff0000'>$data[7]</td>
            <td><input type='text' name='mpercent_{$data[0]}' value={$data[4]} size='3' maxlength='2' onkeypress=\"return OnlyInt()\"> %</td>
           </tr>";
        //return "<tr><td class=paper{$data[0]}>{$data[1]}占成设置</td><td class=td2>{$data[5]}占成\r\n\t\t<input name='percent0_{$data[0]}' value={$data[2]} size='3' maxlength='2' onkeypress=\"return OnlyInt()\"> %&#12288;{$data[5]}收飞最大占成\r\n\t\t<input name='percent2_{$data[0]}' value={$data[3]} size='2' maxlength='2' onkeypress=\"return OnlyInt()\"> %&#12288;{$data[6]}占成\r\n\t\t<input name='mpercent_{$data[0]}' value={$data[4]} size='3' maxlength='2' onkeypress=\"return OnlyInt()\"> %<br>\r\n\t\t<font color=red>● {$data[5]}占成＋{$data[6]}占成不可比  " . $data[7] . " 多</font>\r\n\t\t</td></tr>";
    }

}

class Show_member extends k_users
{

    public function __construct()
    {
        
    }

    public function percent($data)
    {
        return "<tr><td class=paper{$data[0]}>代理商{$data[1]}占成</td><td class=td2>{$data[2]} %</td></tr>";
    }

}

function check_percent_ismodify($id, $gameid, $data)
{
    $rs = getdb("select * from k_user_percent where user_id={$id} and gametype={$gameid} limit 1");
    foreach ($data as $field => $val)
    {
        if ($rs->f[$field] != $val)
        {
            return true;
            break;
        }
    }
    return false;
}

function Check_Percent($id, $gameid, $percent)
{
    if ($id == 0)
    {
        return true;
    }
    $rs = getdb("select id from k_user K left join k_user_percent P ON (P.user_id=K.id and P.gametype={$gameid}) where K.prev_id='" . $id . "' and (P.percent0+P.mpercent) > '" . $percent . "' limit 1");
    $val = $rs->f['id'];
    $rs->close();
    if (isset($val))
    {
        return FALSE;
    }
    return TRUE;
}

function Max_Percent($user, $gametype, $mpercent)
{
    $id = $user->f['id'];
    $acl = $user->f['acl'];
    if ($acl == "3")
    {
        $rs = getdb("update k_user_percent set percent0=(" . $mpercent . "-mpercent),percent1=(" . $mpercent . "-mpercent) " . "where user_id in (select id from k_user where prev_id={$id})");
        return $rs;
    }
    $rs = getdb("update k_user_percent set percent1=" . $mpercent . " where user_id in (select id from k_user where prev_id={$id})");
    return $rs;
}

function getAmount_isused($id, $gametype, $lotto_id)
{
    global $g_gametype_3d;
    static $users = NULL;
    if (!isset($users))
    {
        $users = GetUserList($id);
    }
    if ($users == "")
    {
        return 0;
    }
    switch ($gametype)
    {
        case 0 :
            $rs = getdb("select SUM(amount_6h) FROM `k_user_bet` where user_id in ({$users}) and lotto_id={$lotto_id}");
            break;
        default :
            $rs = getdb("select sum(amount) from bet_{$g_gametype_3d[$gametype]['en']} where user_id in ({$users}) and lotto_id>={$lotto_id} and rame!=2");
            break;
    }
    return $rs->f[0] + 0;
}

function set_modifybook($id, $gameid, $data)
{
    $rs = getdb("!!select * from k_user_percent where user_id={$id} and gametype={$gameid} limit 1");
    if (!$rs->eof)
    {
        $data['percent0_old'] = intval($rs->f['percent0']);
        $data['percent1_old'] = intval($rs->f['percent1']);
        $data['mpercent_old'] = intval($rs->f['mpercent']);
        if ($data['amount_new'] != $data['amount_old'] || $data['mpercent_new'] != $data['mpercent_old'] || $data['percent0_new'] != $data['percent0_old'] || $data['percent1_new'] != $data['percent1_old'])
        {
            db_insert("modifybook", $data);
        }
    }
}

function getUserPercents($id)
{
    global $g_gametype_3d;
    global $conf;
    $percentArr = array ();
    if ($id <= 0)
    {
        foreach ($g_gametype_3d as $gameid => $val)
        {
            switch ($gameid)
            {
                case 0 :
                    $tbl = "";
                    break;
                default :
                    $tbl = "_" . $g_gametype_3d[$gameid]['en'];
                    break;
            }
            $max_all_percent = "max_all_percent" . $tbl;
            $percentArr[$gameid] = array ("percent0" => 0, "percent1" => 0, "percent2" => 0, "mpercent" => intval($conf->get($max_all_percent)), "percent_sw" => 0, "protmod" => 0, "snow_open" => 0);
        }
    }
    else
    {
        $rs = getdb("!!select P.*,K.acl from k_user_percent P left join k_user K ON K.id=P.user_id where P.user_id={$id} order by P.gametype");
        while (!$rs->eof)
        {
            $percentArr[$rs->f['gametype']] = array ("percent0" => intval($rs->f['percent0']), "percent1" => intval($rs->f['percent1']), "percent2" => intval($rs->f['percent2']), "mpercent" => intval($rs->f['mpercent']), "percent_sw" => intval($rs->f['percent_sw']), "protmod" => intval($rs->f['protmod']), "snow_open" => intval($rs->f['snow_open']));
            if ($rs->f['acl'] == 5)
            {
                switch ($rs->f['gametype'])
                {
                    case 0 :
                        $tbl = "";
                        break;
                    default :
                        $tbl = "_" . $g_gametype_3d[$rs->f['gametype']]['en'];
                        break;
                }
                $max_all_percent = "max_all_percent" . $tbl;
                $percentArr[$rs->f['gametype']]['percent1'] = intval($conf->get($max_all_percent));
                $percentArr[$rs->f['gametype']]['percent2'] = 100;
            }
            $rs->Next();
        }
        foreach ($g_gametype_3d as $gameid => $val)
        {
            if (!isset($percentArr[$gameid]))
            {
                $percentArr[$gameid] = array ("percent0" => 0, "percent1" => 0, "percent2" => 0, "mpercent" => 0, "percent_sw" => 0, "protmod" => 0, "snow_open" => 0);
            }
        }
    }
    return $percentArr;
}

function get_percentsw_mode($userid, $gametype = 0)
{
    $info = get_user($userid, $gametype);
    $acl = $info['acl'];
    $pmode = 0;
    switch ($acl)
    {
        case 2 :
            $genagent = get_user($info['prev_id'], $gametype);
            $shareowner = get_user($genagent['prev_id'], $gametype);
            $subsidary = get_user($shareowner['prev_id'], $gametype);
            $pmode = $subsidary['percent_sw'];
            break;
        case 3 :
            $shareowner = get_user($info['prev_id'], $gametype);
            $subsidary = get_user($shareowner['prev_id'], $gametype);
            $pmode = $subsidary['percent_sw'];
            break;
        case 4 :
            $subsidary = get_user($info['prev_id'], $gametype);
            $pmode = $subsidary['percent_sw'];
            break;
        case 5 :
            $pmode = $info['percent_sw'];
            break;
    }
    return $pmode;
}

function get_percentsw_mode2($userid, $gametype = 0)
{
    $info = get_user($userid, $gametype);
    $acl = $info['acl'];
    $pmode = 0;
    switch ($acl)
    {
        case 2 :
            $genagent = get_user($info['prev_id'], $gametype);
            $pmode = $genagent['percent_sw'];
            break;
        case 3 :
            $shareowner = get_user($info['prev_id'], $gametype);
            $pmode = $shareowner['percent_sw'];
            break;
        case 4 :
            $subsidary = get_user($info['prev_id'], $gametype);
            $pmode = $subsidary['percent_sw'];
            break;
        case 5 :
            $pmode = $info['percent_sw'];
            break;
    }
    return $pmode;
}

function get_percentsw_mode3($userid, $gametype = 0)
{
    $info = get_user($userid, $gametype);
    $acl = $info['acl'];
    $pmode = 0;
    switch ($acl)
    {
        case 3 :
            $genagent = get_user($info['id'], $gametype);
            $pmode = $genagent['percent_sw'];
            break;
        case 4 :
            $shareowner = get_user($info['id'], $gametype);
            $pmode = $shareowner['percent_sw'];
            break;
        case 5 :
            $subsidary = get_user($info['id'], $gametype);
            $pmode = $subsidary['percent_sw'];
            break;
    }
    return $pmode;
}

?>